<?php
/**
 * SchoolLine Installer
 *
 * @package WordPress
 * @subpackage Administration
 */

// Sanity check.
if ( false ) {
?>
        <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Error: PHP is not running</title>
</head>
<body>
<h1>Error: PHP is not running</h1>
<p>SchoolLine requires that your web server is running PHP. Your server does not have PHP installed, or PHP is turned off.</p>
</body>
</html>
<?php
}

$step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0;
?>

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>校园院线票务系统安装</title>
</head>
<body>

<?php


$lockfile = "install.lock";

if(file_exists($lockfile)){

    exit("已经安装过了，如果要重新安装请先删除install.lock");

}

if($_GET['action']!=1)

{


?>

<form action="/install" method="get">
    <input type="hidden" value="1" name="action">

    主机地址：<input type="text" name="host" value="localhost"><br>

    用户名:<input type="text" name="user" value="root"><br>

    密码:<input type="password" name="psw" value=""><br>

    数据库名<input type="text" name="db" value="blog"><br>

    提交<input type="submit" value="提交" />

</form>

<?php

}

else

{


    if($_GET['host']!="" && $_GET['user']!="" && $_GET['db']!="")

    {

        $host=$_GET['host'];

        $user=$_GET['user'];

        $psw=$_GET['psw'];

        $db=$_GET['db'];

    }


    $conn=mysqli_connect($host,$user,$psw);

    if($conn)

    {

        $sql_drop_db="Drop DATABASE IF EXISTS `".$db."`";

        $sql_create_db="Create DATABASE `".$db."`";

    }else{
        exit("数据库连接失败");
    }

    mysqli_query($conn,$sql_drop_db);

    mysqli_query($conn,$sql_create_db);

//    env('DB_HOST',$host);
//    env('DB_DATABASE',$db);
//    env('DB_USERNAME',$user);
//    env('DB_PASSWORD',$psw);


    try{

        Artisan::call('config:cache');

        Artisan::call('key:generate');
//        dd('222');
        Artisan::call('migrate');
//        dd('333');
        Artisan::call('db:seed');

        $fp2 = fopen($lockfile, 'w');

        fwrite($fp2,'1212');

        fclose($fp2);
    }catch (\Exception $e){
        exit($e);
    }


}

?>

</body>
</html>